package cn.lili.xiaoran.service.impl;

import cn.lili.xiaoran.entity.LiQuestions;
import cn.lili.xiaoran.mapper.LiQuestionsMapper;
import cn.lili.xiaoran.service.LiQuestionsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * 提问表(LiQuestions)表服务实现类
 *
 * @author makejava
 * @since 2022-08-11 21:33:50
 */
@Service("liQuestionsService")
public class LiQuestionsServiceImpl extends ServiceImpl<LiQuestionsMapper, LiQuestions> implements LiQuestionsService {
    @Resource
    private LiQuestionsMapper liQuestionsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public LiQuestions queryById(Integer id) {
        return this.liQuestionsDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param liQuestions 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<LiQuestions> queryByPage(LiQuestions liQuestions, PageRequest pageRequest) {
        long total = this.liQuestionsDao.count(liQuestions);
        return new PageImpl<>(this.liQuestionsDao.queryAllByLimit(liQuestions, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param liQuestions 实例对象
     * @return 实例对象
     */
    @Override
    public LiQuestions insert(LiQuestions liQuestions) {
        this.liQuestionsDao.insert(liQuestions);
        return liQuestions;
    }

    /**
     * 修改数据
     *
     * @param liQuestions 实例对象
     * @return 实例对象
     */
    @Override
    public LiQuestions update(LiQuestions liQuestions) {
        this.liQuestionsDao.update(liQuestions);
        return this.queryById(liQuestions.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.liQuestionsDao.deleteById(id) > 0;
    }
}
